
//
//  NSMutableArray+Move.m
//  WHPersonalData
//
//  Created by mac on 2019/1/30.
//  Copyright © 2019年 mac. All rights reserved.
//

#import "NSMutableArray+Move.h"

@implementation NSMutableArray (Move)

/*
 方法名:  数组的对象移动
 @param  fromIndex    原下标
 @param  toIndex      新下标
 @return 空
 */

- (void)moveObjectFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex
{
    if (toIndex != fromIndex && fromIndex < [self count] && toIndex< [self count]) {
        
        id obj = [self objectAtIndex:fromIndex];
       
        [self removeObjectAtIndex:fromIndex];
        if (toIndex >= [self count]) {
            [self addObject:obj];
        } else {
            [self insertObject:obj atIndex:toIndex];
        }
    }
}

@end
